package com.itic.mall.mobile.users.store;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.itic.appbase.framework.annotation.CheckLogin;
import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.type.FinanceType;
import com.itic.appbase.framework.type.PreIncomeChannel;
import com.itic.appbase.framework.type.PreType;
import com.itic.appbase.framework.type.TeamLevel;
import com.itic.appbase.framework.type.UserType;
import com.itic.appbase.framework.utils.DateHelper;
import com.itic.appbase.framework.utils.IdGen;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.mall.mobile.base.BaseMobileInterface;
import com.itic.mall.mobile.goods.vo.GoodsDetailVo;
import com.itic.mall.mobile.users.info.FinanceVo;
import com.itic.mall.mobile.users.info.MemberVo;
import com.itic.mall.mobile.users.info.MyTeamVo;
import com.itic.mall.mobile.users.info.PreIncomeVo;
import com.itic.mall.mobile.users.info.SecMemberVo;
import com.itic.mall.mobile.users.info.ShoppingCartVo;
import com.itic.mall.mobile.users.info.StoreGoodsVo;
import com.itic.mall.mobile.users.info.StoreVo;
import com.itic.mall.mobile.users.info.TeamOneVo;
import com.itic.mall.mobile.users.info.UsersAliInfoVo;
import com.itic.mall.mobile.users.info.UsersCollectVo;
import com.itic.mall.mobile.users.info.WithdrawVo;
import com.itic.mall.mobile.users.info.YunUserVo;
import com.itic.mall.mobile.users.store.temp.Condition;
import com.itic.mall.system.goods.coupon.persistence.model.GoodsCoupon;
import com.itic.mall.system.goods.goodssku.service.GoodsSkuService;
import com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpu;
import com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpuExample;
import com.itic.mall.system.goods.goodsspu.service.GoodsSpuService;
import com.itic.mall.system.goods.skucoupon.persistence.model.SkuCoupon;
import com.itic.mall.system.goods.skucoupon.service.SkuCouponService;
import com.itic.mall.system.goods.store.persistence.model.GoodsStore;
import com.itic.mall.system.goods.store.persistence.model.GoodsStoreExample;
import com.itic.mall.system.goods.store.service.GoodsStoreService;
import com.itic.mall.system.msg.apppush.service.AppPushService;
import com.itic.mall.system.msg.type.persistence.model.MsgType;
import com.itic.mall.system.msg.type.service.MsgTypeService;
import com.itic.mall.system.orders.detail.persistence.model.OrdersDetail;
import com.itic.mall.system.orders.detail.persistence.model.OrdersDetailExample;
import com.itic.mall.system.orders.item.persistence.model.OrdersItem;
import com.itic.mall.system.orders.item.persistence.model.OrdersItemExample;
import com.itic.mall.system.orders.orderJD.persistence.model.OrderJD;
import com.itic.mall.system.orders.orderJD.service.OrderJDService;
import com.itic.mall.system.orders.orderJDLeadInto.persistence.model.OrderJDLeadInto;
import com.itic.mall.system.orders.orderJDLeadInto.service.OrderJDLeadIntoService;
import com.itic.mall.system.orders.orderJDProject.persistence.model.OrdersJDProduct;
import com.itic.mall.system.orders.orderJDProject.service.OrdersJDProductService;
import com.itic.mall.system.pay.userlog.persistence.model.PayUserlog;
import com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample;
import com.itic.mall.system.pay.userlog.service.PayUserlogService;
import com.itic.mall.system.store.storeInfo.persistence.model.StoreInfo;
import com.itic.mall.system.store.storeInfo.service.StoreInfoService;
import com.itic.mall.system.users.collection.persistence.model.UsersCollect;
import com.itic.mall.system.users.collection.persistence.model.UsersCollectExample;
import com.itic.mall.system.users.collection.service.UsersCollectService;
import com.itic.mall.system.users.collectionitem.persistence.model.UsersCollectItem;
import com.itic.mall.system.users.collectionitem.persistence.model.UsersCollectItemExample;
import com.itic.mall.system.users.collectionitem.service.UsersCollectItemService;
import com.itic.mall.system.users.openstore.persistence.model.OpenStore;
import com.itic.mall.system.users.openstore.persistence.model.OpenStoreExample;
import com.itic.mall.system.users.openstore.service.OpenStoreService;
import com.itic.mall.system.users.shoppingcart.persistence.model.UsersShoppingCart;
import com.itic.mall.system.users.shoppingcart.persistence.model.UsersShoppingCartExample;
import com.itic.mall.system.users.shoppingcart.service.UsersShoppingCartService;
import com.itic.mall.system.users.shoppingcartitem.persistence.model.UsersShoppingCartItem;
import com.itic.mall.system.users.shoppingcartitem.persistence.model.UsersShoppingCartItemExample;
import com.itic.mall.system.users.shoppingcartitem.service.UsersShoppingCartItemService;
import com.itic.mall.system.users.store.persistence.model.UsersStore;
import com.itic.mall.system.users.store.persistence.model.UsersStoreExample;
import com.itic.mall.system.users.store.service.UsersStoreService;
import com.itic.mall.system.users.usercoupon.persistence.model.UsersCoupon;
import com.itic.mall.system.users.userscode.persistence.model.UsersCode;
import com.itic.mall.system.users.userscode.persistence.model.UsersCodeExample;
import com.itic.mall.system.users.userscode.persistence.model.UsersCodeExample.Criteria;
import com.itic.mall.system.users.userscode.service.UsersCodeService;
import com.itic.mall.system.users.usersmall.persistence.model.UsersMall;
import com.itic.mall.system.users.usersmall.persistence.model.UsersMallExample;
import com.itic.mall.system.users.usersmall.service.UsersMallService;
import com.itic.mall.system.users.userstoken.persistence.model.UsersToken;

/**
 * 用户资料模块接口
 * @author libin
 * @time 2017-12-4
 */

@Controller
@RequestMapping(value="/mobile/users")
public class UserdataInterface extends BaseMobileInterface{
	
	@Autowired
	private UsersStoreService usersStoreService;
	@Autowired
	private GoodsStoreService goodsStoreService;
	@Autowired
	private UsersCollectItemService usersCollectItemService;
	@Autowired
	private PayUserlogService payUserlogService;
	@Autowired
	private UsersMallService usersMallService;
	@Autowired
    private UsersCodeService usersCodeService;
	@Autowired 
	private UsersShoppingCartService usersShoppingCartService;
	@Autowired
	private UsersCollectService usersCollectService;
	@Autowired
	private GoodsSpuService goodsSpuService;
	@Autowired
	private UsersShoppingCartItemService usersShoppingCartItemService;
	@Autowired
	private StoreInfoService storeInfoService;

	@Autowired
	private GoodsSkuService goodsSkuService;
	@Autowired
	private SkuCouponService skuCouponService;
	

	@Autowired
	private MsgTypeService msgTypeService;

	@Autowired
	private AppPushService appPushService;
	@Autowired
	private OrdersJDProductService ordersJDProductService;
	@Autowired
	private OrderJDService ordersJDService;
	@Autowired
	private OrderJDLeadIntoService orderJDLeadIntoService;
	@Autowired
	private OpenStoreService openStoreService;

	/**
	 * APP进入我的页面接口信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/index")
	@ResponseBody
	public Map<String,Object> index( HttpServletRequest request,HttpServletResponse response, String token, String appId ){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	   		String defaultHeadImg=sysSettingService.getByKey("DEFAULT_HEAD_IMAGE");
	    	if( StringHelper.isNotBlank(token) && StringHelper.isNotBlank(appId) ){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    		Map<String, Object> dataMap = new HashMap<String,Object>();
	    		Map<String, Object> storeMap = new HashMap<String,Object>();
		    	if( null != usersMall ){
		    		//是否是云店主
		    		String type = usersMall.getType();
		    		if("002".equals(type)){
		    			storeMap.put("preProfit", usersMall.getPreProfit());
		    			storeMap.put("totalProfit", usersMall.getTotalProfit());
		    			storeMap.put("order", 0);
		    		}
		    		int collection = 0;
		    		int shoppingCart = 0; 
		    		String userId = usersMall.getId();
		    		UsersShoppingCartExample examplecart = new UsersShoppingCartExample();
		    		com.itic.mall.system.users.shoppingcart.persistence.model.UsersShoppingCartExample.Criteria criteriacart = examplecart.createCriteria();
		    		criteriacart.andIsEffectiveEqualTo(DBConst.TRUE);
		    		criteriacart.andUserIdEqualTo(userId);
		    		List<UsersShoppingCart> listcart = usersShoppingCartService.list(examplecart);
		    		if(listcart.size()>0){
		    			shoppingCart = listcart.size();
		    		}
		    		UsersCollectExample examplec = new UsersCollectExample();
		    		com.itic.mall.system.users.collection.persistence.model.UsersCollectExample.Criteria criteriac = examplec.createCriteria();
		    		criteriac.andIsEffectiveEqualTo(DBConst.TRUE);
		    		criteriac.andUserIdEqualTo(userId);
		    		List<UsersCollect> listc = usersCollectService.list(examplec);
		    		if(listc.size()>0){
		    			collection = listc.size();
		    		}
		    		dataMap.put("collection", collection);
		    		dataMap.put("shoppingCart",shoppingCart);
		    		dataMap.put("userNickname", usersMall.getUserNickName()==null?"未定义":usersMall.getUserNickName());//用户名称
					dataMap.put("userHeadimg", usersMall.getUserHeadImg()==null?defaultHeadImg:usersMall.getUserHeadImg());//用户头像
					dataMap.put("vipLevel", usersMall.getVipLevel()==null?"0":usersMall.getVipLevel());//vip等级
					dataMap.put("money", usersMall.getMoney()==null?"0":usersMall.getMoney());//可用余额
					dataMap.put("jifeng", usersMall.getJifeng()==null?"0":usersMall.getJifeng());//惠金币JIFENG	   				
					List<MsgType> msgTypes = this.msgTypeService.getParentMsgType();
					int notReadCount=0;
					for(MsgType msgType :msgTypes) {
						notReadCount += this.appPushService.getNotReadCountByTypeId(msgType,usersMall.getId());
					}
					dataMap.put("notReadCount", notReadCount);
					resultMap.put("userinfo", dataMap);
 		    		resultMap.put("store", storeMap);
		    		errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
		    	}else{
		    		errorCode = LOGIN_ERROR_CODE;
			       	errorMsg = LOGIN_ERROR_MSG;
		    	}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "index", e.toString(),"APP进入我的页面接口信息",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	/**
	 * 生钱
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/myincomefinacelog")
	@ResponseBody
	public Map<String,Object> myincomefinacelog( HttpServletRequest request,HttpServletResponse response, String token, String appId ){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    List<FinanceVo> listincome = new ArrayList<FinanceVo>();
		try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			PayUserlogExample example = new PayUserlogExample();
    			com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample.Criteria criteria = example.createCriteria();
    			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    			criteria.andUserIdEqualTo(userId);
    			criteria.andTypeEqualTo("001");//账务类型（001：收入，002：支出）
    			//criteria.andIncomeTypeEqualTo("001");//收入类型(001:友惠钱包利息，002：京东联盟返利)
    			List<PayUserlog> list = payUserlogService.list(example);
    			if(list.size()>0){
    				for(PayUserlog payUserlog:list){
    					FinanceVo financeVo = new FinanceVo();
    					financeVo.setAmount(payUserlog.getAmount());
    					String incomeType = payUserlog.getIncomeType();
    					//根据消费类型获取消费名称
    					String name = getNameByType(incomeType);
    					financeVo.setName(name);
    					financeVo.setTime(payUserlog.getPayTime());
    					listincome.add(financeVo);
    				}
    				errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
					resultMap.put(DATA, listincome);
    			}
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
		}catch(Exception e){
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "myincomefinacelog", e.toString(),"生钱",e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
		}
	
	/**
	 * 花钱
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/myoutfinacelog")
	@ResponseBody
	public Map<String,Object> myoutfinacelog( HttpServletRequest request,HttpServletResponse response, String token, String appId ){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    List<FinanceVo> listout = new ArrayList<FinanceVo>();
		try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			PayUserlogExample example = new PayUserlogExample();
    			com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample.Criteria criteria = example.createCriteria();
    			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    			criteria.andUserIdEqualTo(userId);
    			criteria.andTypeEqualTo("002");//账务类型（001：收入，002：支出）
    			List<PayUserlog> list = payUserlogService.list(example);
    			if(list.size()>0){
    				for(PayUserlog payUserlog:list){
    					FinanceVo financeVo = new FinanceVo();
    					financeVo.setAmount(payUserlog.getAmount());
    					String outType = payUserlog.getPayType();
    					//根据消费类型获取消费名称
    					String name = getNameByType(outType);
    					financeVo.setName(name);
    					financeVo.setTime(payUserlog.getPayTime());
    					listout.add(financeVo);
    				}
    				errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
					resultMap.put(DATA, listout);
    			}
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
		}catch(Exception e){
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "myoutfinacelog", e.toString(),"花钱",e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
		}
	/**
   	 * 根据订单号获取订单支付时间
   	 * @param orderNo
   	 * @return
   	 */
       public Date getOrderTime(String orderNo){
    	Date date = new Date();
       	PayUserlogExample example = new PayUserlogExample();
		com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andOrderNoEqualTo(orderNo);
		List<PayUserlog> list = payUserlogService.list(example);
   		if(list.size()>0){
   			date = list.get(0).getPayTime();
   		}
   		return date;
       }
       
	/**
	 * 根据用户ID获取商品信息，用户信息和支付日志信息
	 * 
	 * @param orderNo
	 * @param goodsId
	 * @return
	 */
	public List<PreIncomeVo> getPreDetail(String userId,String preTytpe) {
		List<PreIncomeVo> itemlist = new ArrayList<PreIncomeVo>();
		if (StringHelper.isNotBlank(userId)) {
			// 获取支付日志信息
			PayUserlogExample example = new PayUserlogExample();
			com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample.Criteria criteria = example
					.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
			criteria.andUserIdEqualTo(userId);
			criteria.andPreTypeEqualTo(preTytpe);// 预估标识（001：预估，002：实际）
			List<PayUserlog> list = payUserlogService.list(example);
			if (list.size() > 0) {
				for (PayUserlog payUserlog : list) {
					PreIncomeVo preIncomeVo = new PreIncomeVo();
					// 从用户支付日志中获取预估收益类型，预估收益渠道编码
					String preType = payUserlog.getPreIncomeType();
					String preIncomeCode = payUserlog.getPreIncomeChannel();
					// 根据预估收益渠道编码获取渠道名称
					String preIncomename = getNameByType(preIncomeCode);
					String preTypename = getNameByType(preType);
					preIncomeVo.setPreIncomename(preIncomename);
					preIncomeVo.setPreTypename(preTypename);
					// 订单号
					String orderNo = payUserlog.getOrderNo();
					String goodsId = payUserlog.getSkuId();
					preIncomeVo.setOrderNo(orderNo);
					preIncomeVo.setOrderTime(payUserlog.getPayTime());
					// 根据订单号取下单人姓名
					String userNickName = getUserNameByOrderNo(orderNo);
					preIncomeVo.setUserNickName(userNickName);
					// 根据商品号获取该商品的佣金
					GoodsSpuExample goodsSpuExample = new GoodsSpuExample();
					com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpuExample.Criteria goodsSpucriteria = goodsSpuExample
							.createCriteria();
					goodsSpucriteria.andIsEffectiveEqualTo(DBConst.TRUE);
					goodsSpucriteria.andIdEqualTo(goodsId);
					List<GoodsSpu> goodsSpulist = goodsSpuService.list(goodsSpuExample);
					if (goodsSpulist.size() > 0) {
						preIncomeVo.setProfitAmount(goodsSpulist.get(0).getMarketProfit());
					}
					// 订单项信息
					OrdersItemExample exampleitem = new OrdersItemExample();
					com.itic.mall.system.orders.item.persistence.model.OrdersItemExample.Criteria criteriao = exampleitem
							.createCriteria();
					criteriao.andIsEffectiveEqualTo(DBConst.TRUE);
					criteriao.andOrderNoEqualTo(orderNo);
					criteriao.andGoodsIdEqualTo(goodsId);
					List<OrdersItem> listo = ordersItemService.list(exampleitem);
					if (listo.size() > 0) {
						// 根据订单号获取订单项下所有购买商品，每一个订单项作为一条记录，获取商品名称，购买用户名称，实付金额
						preIncomeVo.setActualPay(listo.get(0).getPrice());
						preIncomeVo.setGoodsName(listo.get(0).getGoodsName());
					}
					itemlist.add(preIncomeVo);
				}
			}
		}
		return itemlist;
	}
	
	
	/**
	 * 根据用户ID和时间段获取商品信息，用户信息和支付日志信息
	 * @param token
	 * @param appId
	 * @param preTytpe
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public List<PreIncomeVo> getDetailByTime(String userId,String preTytpe,Date startTime,Date endTime) {
		List<PreIncomeVo> itemlist = new ArrayList<PreIncomeVo>();
		try {

			if (StringHelper.isNotBlank(userId) && startTime != null && endTime != null) {
				// 获取支付日志信息
				PayUserlogExample example = new PayUserlogExample();
				com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample.Criteria criteria = example
						.createCriteria();
				criteria.andIsEffectiveEqualTo(DBConst.TRUE);
				criteria.andUserIdEqualTo(userId);
				criteria.andPreTypeEqualTo(preTytpe);// 预估标识（001：预估，002：实际）
				criteria.andPayTimeBetween(startTime, endTime);
				List<PayUserlog> list = payUserlogService.list(example);
				if (list.size() > 0) {
					for (PayUserlog payUserlog : list) {
						PreIncomeVo preIncomeVo = new PreIncomeVo();
						// 从用户支付日志中获取预估收益类型，预估收益渠道编码
						String preType = payUserlog.getPreIncomeType();
						String preIncomeCode = payUserlog.getPreIncomeChannel();
						// 根据预估收益渠道编码获取渠道名称
						String preIncomename = getNameByType(preIncomeCode);
						String preTypename = getNameByType(preType);
						preIncomeVo.setPreIncomename(preIncomename);
						preIncomeVo.setPreTypename(preTypename);
						// 订单号
						String orderNo = payUserlog.getOrderNo();
						String goodsId = payUserlog.getSkuId();
						preIncomeVo.setOrderNo(orderNo);
						preIncomeVo.setOrderTime(payUserlog.getPayTime());
						// 根据订单号取下单人姓名
						String userNickName = getUserNameByOrderNo(orderNo);
						preIncomeVo.setUserNickName(userNickName);
						// 根据商品号获取该商品的佣金
						GoodsSpuExample goodsSpuExample = new GoodsSpuExample();
						com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpuExample.Criteria goodsSpucriteria = goodsSpuExample
								.createCriteria();
						goodsSpucriteria.andIsEffectiveEqualTo(DBConst.TRUE);
						goodsSpucriteria.andIdEqualTo(goodsId);
						List<GoodsSpu> goodsSpulist = goodsSpuService.list(goodsSpuExample);
						if (goodsSpulist.size() > 0) {
							preIncomeVo.setProfitAmount(goodsSpulist.get(0).getMarketProfit());
						}
						// 订单项信息
						OrdersItemExample exampleitem = new OrdersItemExample();
						com.itic.mall.system.orders.item.persistence.model.OrdersItemExample.Criteria criteriao = exampleitem
								.createCriteria();
						criteriao.andIsEffectiveEqualTo(DBConst.TRUE);
						criteriao.andOrderNoEqualTo(orderNo);
						criteriao.andGoodsIdEqualTo(goodsId);
						List<OrdersItem> listo = ordersItemService.list(exampleitem);
						if (listo.size() > 0) {
							// 根据订单号获取订单项下所有购买商品，每一个订单项作为一条记录，获取商品名称，购买用户名称，实付金额
							preIncomeVo.setActualPay(listo.get(0).getPrice());
							preIncomeVo.setGoodsName(listo.get(0).getGoodsName());
						}
						itemlist.add(preIncomeVo);
					}
				}
			}

		}catch(Exception e){
	   		logException("UserdataInterface", "getPreDetailByTime", e.toString(),"根据用户ID和时间段获取商品信息，用户信息和支付日志信息",e);
		}
		
		return itemlist;
	}

	/**
	 * 根据用户id获取累计预估或者实际收益
	 * 
	 * @param userId
	 * @param preTytpe
	 * @return
	 */
	public int getPreOrActualNum(String userId, String preTytpe) {
		int totalNum = 0;
		try {
			if (StringHelper.isNotBlank(userId)) {
				// 获取支付日志信息
				PayUserlogExample example = new PayUserlogExample();
				com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample.Criteria criteria = example
						.createCriteria();
				criteria.andIsEffectiveEqualTo(DBConst.TRUE);
				criteria.andUserIdEqualTo(userId);
				criteria.andPreTypeEqualTo(preTytpe);// 预估标识（001：预估，002：实际）
				List<PayUserlog> list = payUserlogService.list(example);
				if(list.size()>0){
					totalNum = list.size();
				}
			}
		} catch (Exception e) {
		}
		return totalNum;
	}
	public int getOrderNum(String yunUserId){
		int orderNum = 0;
		if(StringHelper.isNotBlank(yunUserId)){
			OrdersDetailExample example = new OrdersDetailExample();
			com.itic.mall.system.orders.detail.persistence.model.OrdersDetailExample.Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
			criteria.andYunUserIdEqualTo(yunUserId);
			List<OrdersDetail> list = ordersDetailService.list(example);
			if(list.size()>0){
				orderNum = list.size();
			}
		}
		return orderNum;
	}
	/**
	 * 云店主店铺信息页面
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/yunindex")
	@ResponseBody
	@CheckLogin
	public Map<String,Object> yunindex( HttpServletRequest request,HttpServletResponse response, String token, String appId ){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
		Map<String, Object> resultMap = new HashMap<String,Object>();
	   	try{
	   		UsersMall usersMall = this.CurUsersMall(request);
	   		if(usersMall != null) {
	   			//云店主
	   			if(UserType.isYDZ(usersMall.getType())) {
	   				YunUserVo yunUserVo = this.usersMallWrapYunUserVo(usersMall);
	   				resultMap.put(DATA, yunUserVo);
	   				errorCode = SUCCESS_ERROR_CODE;
	   				errorMsg = SUCCESS_ERROR_MSG;
	   			}else {
	   				errorCode = Not_OPEND_YDZ_ERROR_CODE;
	   				errorMsg = Not_OPEND_YDZ_ERROR_MSG;
	   			}
	   		}else {
	   			errorCode = LOGIN_ERROR_CODE;
	   			errorMsg = LOGIN_ERROR_MSG;
	   		}
	   	}catch(Exception e){
	   		errorCode = SERVER_ERROR_CODE;
	   		errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "yunindex", e.toString(),"云店主店铺信息页面",e);
	   	}
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	  }
	/**
	 * 获取我的团队头部信息
	 * @param token
	 * @param appId
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value="/getMyteamHead")
	@ResponseBody
	public Map<String, Object> getMyteamHead( HttpServletRequest request,HttpServletResponse response,String token, String appId) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			Condition condition = new Condition();
    			condition.setLevel(TeamLevel.One.getLevel());
    			condition.setParentId(usersMall.getId());
    			int myteamOne = this.usersMallService.getCountByLevel(condition);
    			condition.setLevel(TeamLevel.Two.getLevel());
    			int myteamTwo = this.usersMallService.getCountByLevel(condition);
				int invitedCount = this.usersMallService.getInviteRecordCount(usersMall.getId());
				resultMap.put("myteamOne", myteamOne);
				resultMap.put("myteamTwo", myteamTwo);
				resultMap.put("invitedCount", invitedCount);
				errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getMyteamHead", e.toString(),"获取我的团队头部信息",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	/**
	 * 获取我的一级团队
	 * @param token
	 * @param appId
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value="/getMyteamOne")
	@ResponseBody
	public Map<String, Object> getMyteamOne( HttpServletRequest request,HttpServletResponse response,String token, String appId) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    List<TeamOneVo> teamList = new ArrayList<TeamOneVo>();
	    try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			List<UsersMall> list = getusersTeam(userId);
    			if(list.size()>0){
    				for(UsersMall users:list){
        				TeamOneVo teamOneVo = new TeamOneVo();
        				teamOneVo.setCreatTime(users.getCreateTime());
        				//根据一级成员ID查询该成员下的下级
        				int teamNum = getTeamNum(users.getId());
        				teamOneVo.setTeamNum(teamNum);
        				teamOneVo.setUserName(users.getUserNickName());
        				teamOneVo.setUserPhone(users.getUserPhone());
        				teamList.add(teamOneVo);
    				} 
    				resultMap.put(DATA, teamList);
    			}
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getMyteamOne", e.toString(),"获取我的一级团队",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	/**
	 * 根据时间段查询我的一级团队
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/getMyteamOneByTime")
	@ResponseBody
	public Map<String, Object> getMyteamOneByTime( HttpServletRequest request,HttpServletResponse response,String token, String appId,Date startTime,Date endTime) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    List<TeamOneVo> teamList = new ArrayList<TeamOneVo>();
	    try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			String start = String.valueOf(startTime);
    			String end = String.valueOf(endTime);
    			if(!start.equals("null") || !end.equals("null")){
    				List<UsersMall> list = getusersTeamByTime(userId,startTime,endTime);
        			if(list.size()>0){
        				for(UsersMall users:list){
            				TeamOneVo teamOneVo = new TeamOneVo();
            				teamOneVo.setCreatTime(users.getCreateTime());
            				//根据一级成员ID查询该成员下的下级
            				int teamNum = getTeamNum(users.getId());
            				teamOneVo.setTeamNum(teamNum);
            				teamOneVo.setUserName(users.getUserNickName());
            				teamOneVo.setUserPhone(users.getUserPhone());
            				teamList.add(teamOneVo);
        				} 
        				resultMap.put(DATA, teamList);
        			}
        			errorCode = SUCCESS_ERROR_CODE;
        			errorMsg = SUCCESS_ERROR_MSG;
    			}
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getMyteamOneByTime", e.toString(),"根据时间段查询我的一级团队",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	/**
	 * 根据用户名或电话查询我的一级团队
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value="/getMyteamOneByMsg")
	@ResponseBody
	public Map<String, Object> getMyteamOneByMsg( HttpServletRequest request,HttpServletResponse response,String token, String appId,String userName,String userPhone) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    List<TeamOneVo> teamList = new ArrayList<TeamOneVo>();
	    try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			if(StringHelper.isNotBlank(userName) || StringHelper.isNotBlank(userPhone)){
    				List<UsersMall> list = getusersTeamByMsg(userId,userName,userPhone);
        			if(list.size()>0){
        				for(UsersMall users:list){
            				TeamOneVo teamOneVo = new TeamOneVo();
            				teamOneVo.setCreatTime(users.getCreateTime());
            				//根据一级成员ID查询该成员下的下级
            				int teamNum = getTeamNum(users.getId());
            				teamOneVo.setTeamNum(teamNum);
            				teamOneVo.setUserName(users.getUserNickName());
            				teamOneVo.setUserPhone(users.getUserPhone());
            				teamList.add(teamOneVo);
        				} 
        				resultMap.put(DATA, teamList);
        			}
        			errorCode = SUCCESS_ERROR_CODE;
        			errorMsg = SUCCESS_ERROR_MSG;
    			}
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getMyteamOneByMsg", e.toString(),"根据用户名或电话查询我的一级团队",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	
	/**
	 * 获取团队信息
	 * @param parentId
	 * @return
	 */
	@RequestMapping(value="/teamDetail")
	@ResponseBody
	public Map<String, Object> teamDetail( HttpServletRequest request,HttpServletResponse response,String parentId) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	List<MemberVo> memberList = new ArrayList<MemberVo>();
	    	//根据上级名称获取用户团队名称
	    	String teamName = getUserName(parentId);
	    	int teamNum = 0;
			List<UsersMall> teamlist = getusersTeam(parentId);
			if(teamlist.size()>0){
				teamNum = teamlist.size();
				MyTeamVo myTeamVo = new MyTeamVo();
				myTeamVo.setTeamName(teamName);
				myTeamVo.setTeamNum(teamNum);
				for(UsersMall usersMall:teamlist){
					MemberVo memberVo = new MemberVo();
					memberVo.setCreateTime(usersMall.getCreateTime());
					memberVo.setMemberName(usersMall.getUserNickName());
					memberVo.setMemberPhone(usersMall.getUserPhone());
					memberList.add(memberVo);
				}
				myTeamVo.setMemberList(memberList);
				resultMap.put(DATA, myTeamVo);
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "teamDetail", e.toString(),"获取团队信息",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	/**
	 * 获取我的二级团队
	 * @param token
	 * @param appId
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value="/getMyteamTwo")
	@ResponseBody
	public Map<String, Object> getMyteamTwo( HttpServletRequest request,HttpServletResponse response,String token, String appId) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	List<SecMemberVo> totalList = new ArrayList<SecMemberVo>();
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			List<UsersMall> list = getusersTeam(userId);
    			if(list.size()>0){
    				for(UsersMall users:list){
    					//根据一级下级的用户ID未父ID获取，该一级用户下的所有下级用户
    					String parentId = users.getId();
    					List<UsersMall> memberList = getusersTeam(parentId);
    					if(memberList.size()>0){
    						for(UsersMall members:memberList){
    							String parentName = getUserName(members.getParentId());
    							SecMemberVo secMemberVo = new SecMemberVo();
    							secMemberVo.setCreateTime(members.getCreateTime());
    							secMemberVo.setMemberName(members.getUserNickName());
    							secMemberVo.setMemberPhone(members.getUserPhone());
    							secMemberVo.setParentName(parentName);
    	    					totalList.add(secMemberVo);
    						}
    					}
    				} 
    			}
    			resultMap.put(DATA, totalList);
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;   		
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getMyteamTwo", e.toString(),"获取我的二级团队",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	/**
	 * 根据时间段获取我的二级团队
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/getMyteamTwoByTime")
	@ResponseBody
	public Map<String, Object> getMyteamTwoByTime( HttpServletRequest request,HttpServletResponse response,String token, String appId,Date startTime,Date endTime) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	List<SecMemberVo> totalList = new ArrayList<SecMemberVo>();
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			List<UsersMall> list = getusersTeam(userId);
    			if(list.size()>0){
    				for(UsersMall users:list){
    					//根据一级下级的用户ID未父ID获取，该一级用户下的所有下级用户
    					String parentId = users.getId();
    					String start = String.valueOf(startTime);
    	    			String end = String.valueOf(endTime);
    	    			if(!start.equals("null") || !end.equals("null")){
    	    				List<UsersMall> memberList = getusersTeamByTime(parentId,startTime,endTime);
        					if(memberList.size()>0){
        						for(UsersMall members:memberList){
        							String parentName = getUserName(members.getParentId());
        							SecMemberVo secMemberVo = new SecMemberVo();
        							secMemberVo.setCreateTime(members.getCreateTime());
        							secMemberVo.setMemberName(members.getUserNickName());
        							secMemberVo.setMemberPhone(members.getUserPhone());
        							secMemberVo.setParentName(parentName);
        	    					totalList.add(secMemberVo);
        						}
        					}
    	    			}
    					
    				} 
    			}
    			resultMap.put(DATA, totalList);
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;   		
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getMyteamTwoByTime", e.toString(),"根据时间段获取我的二级团队",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	/**
	 * 根据电话或者姓名获取团队二级信息
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param userName
	 * @param userPhone
	 * @return
	 */
	@RequestMapping(value="/getMyteamTwoByMsg")
	@ResponseBody
	public Map<String, Object> getMyteamTwoByMsg( HttpServletRequest request,HttpServletResponse response,String token, String appId,String userName,String userPhone) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	List<SecMemberVo> totalList = new ArrayList<SecMemberVo>();
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			List<UsersMall> list = getusersTeam(userId);
    			if(list.size()>0){
    				for(UsersMall users:list){
    					//根据一级下级的用户ID未父ID获取，该一级用户下的所有下级用户
    					String parentId = users.getId();
    	    			if(StringHelper.isNotBlank(userName) || StringHelper.isNotBlank(userPhone)){
    	    				List<UsersMall> memberList = getusersTeamByMsg(parentId,userName,userPhone);
        					if(memberList.size()>0){
        						for(UsersMall members:memberList){
        							String parentName = getUserName(members.getParentId());
        							SecMemberVo secMemberVo = new SecMemberVo();
        							secMemberVo.setCreateTime(members.getCreateTime());
        							secMemberVo.setMemberName(members.getUserNickName());
        							secMemberVo.setMemberPhone(members.getUserPhone());
        							secMemberVo.setParentName(parentName);
        	    					totalList.add(secMemberVo);
        						}
        					}
    	    			}	
    				} 
    			}
    			resultMap.put(DATA, totalList);
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;   		
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getMyteamTwoByTime", e.toString(),"根据电话或者姓名获取团队二级信息",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	/**
	 * 提现明细
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param userName
	 * @param userPhone
	 * @return
	 */
	@RequestMapping(value="/withdrawDetail")
	@ResponseBody
	public Map<String, Object> withdrawDetail( HttpServletRequest request,HttpServletResponse response,String token, String appId) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		List<WithdrawVo> drawList = new ArrayList<WithdrawVo>();
    		if(usersMall != null){
    			PayUserlogExample example = new PayUserlogExample();
    			com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample.Criteria criteria = example.createCriteria();
    			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    			criteria.andTypeEqualTo(FinanceType.Reflect.getType());
    			criteria.andUserIdEqualTo(usersMall.getId());
    			example.setOrderByClause("create_time desc");
    			this.handlePageQueryDefault(request, example);
    			List<PayUserlog> list = payUserlogService.list(example);
    			int count = payUserlogService.count(example);
    			double totalAmount = 0;
    			if(!list.isEmpty()){
    				for(PayUserlog payUserlog:list){
    	    	    	WithdrawVo withdrawVo = new WithdrawVo();
    	    	    	withdrawVo.setFailReason(payUserlog.getWithdrawFailReason());
    	    	    	withdrawVo.setAmount(payUserlog.getAmount());
    	    	    	double free = payUserlog.getWithdrawFee()==null?0:payUserlog.getWithdrawFee();
        	    	    withdrawVo.setChargeFee(free);
    	    	    	withdrawVo.setRemindMsg(payUserlog.getWithdrawRemind());
    	    	    	withdrawVo.setTime(payUserlog.getPayTime());
    	    	    	drawList.add(withdrawVo);
    				}
    				totalAmount = list.get(0).getWithdrawTotalAmount()==null?0:list.get(0).getWithdrawTotalAmount();
    			}
    			Map<String, Object> dataMap = new HashMap<>();
    			dataMap.put("withdrawList", drawList);
    			dataMap.put("totalAmount", totalAmount);
    			dataMap.put("total", count);
    			resultMap.put(DATA, dataMap);
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "withdrawDetail", e.toString(),"提现明细",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	/**
	 * 获取店主推荐商品
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value = "/ownerRecomGoods")
	@ResponseBody
	public Map<String, Object> ownerRecomGoods(HttpServletRequest request, HttpServletResponse response, String token,String appId) {
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			List<StoreGoodsVo> storeList = new ArrayList<StoreGoodsVo>();
    			String userId = usersMall.getId();
    			UsersStoreExample example = new UsersStoreExample();
    			com.itic.mall.system.users.store.persistence.model.UsersStoreExample.Criteria criteria = example.createCriteria();
    			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    			criteria.andUserIdEqualTo(userId);
    			criteria.andIsOwnerRecomEqualTo("1"); 
    			List<UsersStore> list = usersStoreService.list(example);
    			if(list.size()>0){
    				for(UsersStore usersStore:list){
    					String goodsId = usersStore.getGoodsId();
    					StoreGoodsVo storeGoodsVo = getstoreGoods(userId,goodsId);
    					storeList.add(storeGoodsVo);
    				}
    			}
    			resultMap.put(DATA, storeList);
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "ownerRecomGoods", e.toString(),"获取店主推荐商品",e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	/**
	 * 获取店铺爆款商品
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value = "/storeHotGoods")
	@ResponseBody
	public Map<String, Object> storeHotGoods(HttpServletRequest request, HttpServletResponse response, String token,String appId) {
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			List<StoreGoodsVo> storeList = new ArrayList<StoreGoodsVo>();
    			String userId = usersMall.getId();
    			UsersStoreExample example = new UsersStoreExample();
    			com.itic.mall.system.users.store.persistence.model.UsersStoreExample.Criteria criteria = example.createCriteria();
    			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    			criteria.andUserIdEqualTo(userId);
    			criteria.andIsOwnerRecomEqualTo("1"); 
    			List<UsersStore> list = usersStoreService.list(example);
    			if(list.size()>0){
    				for(UsersStore usersStore:list){
    					String goodsId = usersStore.getGoodsId();
    					StoreGoodsVo storeGoodsVo = getHotGoods(userId,goodsId);
    					storeList.add(storeGoodsVo);
    				}
    			}
    			resultMap.put(DATA, storeList);
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
		
		}catch(Exception e){
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "storeHotGoods", e.toString(),"获取店铺爆款商品",e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
		}
	/**
	 * 根据时间段获取商品信息，用户预估收益信息
	 * @param token
	 * @param appId
	 * @param preTytpe
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value="/getpreDetailByTime")
	@ResponseBody
	public Map<String, Object> getpreDetailByTime( HttpServletRequest request,HttpServletResponse response,String token, String appId,Date startTime,Date endTime) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
		List<PreIncomeVo> itemlist = new ArrayList<PreIncomeVo>();
		try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			itemlist = getDetailByTime(userId,"001", startTime,endTime);
    			resultMap.put(DATA, itemlist);
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
		}catch(Exception e){
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getpreDetailByTime", e.toString(),"根据时间段获取商品信息，用户预估收益信息",e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
		}
	
	/**
	 * 根据时间段获取商品信息，用户累计收益信息
	 * @param token
	 * @param appId
	 * @param preTytpe
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value="/getActualDetailByTime")
	@ResponseBody
	public Map<String, Object> getActualDetailByTime( HttpServletRequest request,HttpServletResponse response,String token, String appId,Date startTime,Date endTime) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
		List<PreIncomeVo> itemlist = new ArrayList<PreIncomeVo>();
		try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			itemlist = getDetailByTime(userId,"002", startTime,endTime);
    			resultMap.put(DATA, itemlist);
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
		}catch(Exception e){
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getActualDetailByTime", e.toString(),"根据时间段获取商品信息，用户累计收益信息",e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
		}
	
	/**
	 * 根据订单号获取商品信息，用户信息和支付日志信息
	 * @param token
	 * @param appId
	 * @param preTytpe
	 * @param orderNo
	 * @return
	 */
	@RequestMapping(value="/getDetailByOrderNo")
	@ResponseBody
	public List<PreIncomeVo> getDetailByOrderNo(String userId,String preTytpe,String orderNo) {
		List<PreIncomeVo> itemlist = new ArrayList<PreIncomeVo>();
		try {
			if (StringHelper.isNotBlank(userId) && StringHelper.isNotBlank(orderNo)) {
				// 获取支付日志信息
				PayUserlogExample example = new PayUserlogExample();
				com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample.Criteria criteria = example
						.createCriteria();
				criteria.andIsEffectiveEqualTo(DBConst.TRUE);
				criteria.andUserIdEqualTo(userId);
				criteria.andPreTypeEqualTo(preTytpe);// 预估标识（001：预估，002：实际）
				criteria.andOrderNoEqualTo(orderNo);
				List<PayUserlog> list = payUserlogService.list(example);
				if (list.size() > 0) {
					for (PayUserlog payUserlog : list) {
						PreIncomeVo preIncomeVo = new PreIncomeVo();
						// 从用户支付日志中获取预估收益类型，预估收益渠道编码
						String preType = payUserlog.getPreIncomeType();
						String preIncomeCode = payUserlog.getPreIncomeChannel();
						// 根据预估收益渠道编码获取渠道名称
						String preIncomename = getNameByType(preIncomeCode);
						String preTypename = getNameByType(preType);
						preIncomeVo.setPreIncomename(preIncomename);
						preIncomeVo.setPreTypename(preTypename);
						// 订单号
						String goodsId = payUserlog.getSkuId();
						preIncomeVo.setOrderNo(orderNo);
						preIncomeVo.setOrderTime(payUserlog.getPayTime());
						// 根据订单号取下单人姓名
						String userNickName = getUserNameByOrderNo(orderNo);
						preIncomeVo.setUserNickName(userNickName);
						// 根据商品号获取该商品的佣金
						GoodsSpuExample goodsSpuExample = new GoodsSpuExample();
						com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpuExample.Criteria goodsSpucriteria = goodsSpuExample
								.createCriteria();
						goodsSpucriteria.andIsEffectiveEqualTo(DBConst.TRUE);
						goodsSpucriteria.andIdEqualTo(goodsId);
						List<GoodsSpu> goodsSpulist = goodsSpuService.list(goodsSpuExample);
						if (goodsSpulist.size() > 0) {
							preIncomeVo.setProfitAmount(goodsSpulist.get(0).getMarketProfit());
						}
						// 订单项信息
						OrdersItemExample exampleitem = new OrdersItemExample();
						com.itic.mall.system.orders.item.persistence.model.OrdersItemExample.Criteria criteriao = exampleitem
								.createCriteria();
						criteriao.andIsEffectiveEqualTo(DBConst.TRUE);
						criteriao.andOrderNoEqualTo(orderNo);
						criteriao.andGoodsIdEqualTo(goodsId);
						List<OrdersItem> listo = ordersItemService.list(exampleitem);
						if (listo.size() > 0) {
							// 根据订单号获取订单项下所有购买商品，每一个订单项作为一条记录，获取商品名称，购买用户名称，实付金额
							preIncomeVo.setActualPay(listo.get(0).getPrice());
							preIncomeVo.setGoodsName(listo.get(0).getGoodsName());
						}
						itemlist.add(preIncomeVo);
					}

				}
			}

		}catch(Exception e){
	   		logException("UserdataInterface", "getDetailByOrderNo", e.toString(),"根据订单号获取商品信息，用户信息和支付日志信息",e);
		}
		
		return itemlist;
	}
	/**
	 * 根据用户订单号获取预估收益信息
	 * @param token
	 * @param appId
	 * @param preTytpe
	 * @param orderNo
	 * @return
	 */
	@RequestMapping(value="/getPreDetailByOrderNo")
	@ResponseBody
	public Map<String, Object> getPreDetailByOrderNo( HttpServletRequest request,HttpServletResponse response,String token, String appId,String preTytpe,String orderNo) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
		try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			List<PreIncomeVo> list = getDetailByOrderNo(userId,"001",orderNo);
    			resultMap.put(DATA, list);
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
		}catch(Exception e){
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getPreDetailByOrderNo", e.toString(),"根据订单号获取商品信息，用户信息和支付日志信息",e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
		}
	/**
	 * 根据订单号获取用户实际收益信息
	 * @param token
	 * @param appId
	 * @param preTytpe
	 * @param orderNo
	 * @return
	 */
	@RequestMapping(value="/getActualDetailByOrderNo")
	@ResponseBody
	public Map<String, Object> getActualDetailByOrderNo( HttpServletRequest request,HttpServletResponse response,String token, String appId,String preTytpe,String orderNo) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
		try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			List<PreIncomeVo> list = getDetailByOrderNo(userId,"002",orderNo);
    			resultMap.put(DATA, list);
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
		}catch(Exception e){
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getActualDetailByOrderNo", e.toString(),"根据订单号获取用户实际收益信息",e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
		}
	
	/**
	 * 预估收益明细
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/mypreincomelog")
	@ResponseBody
	public Map<String,Object> mypreincomelog( HttpServletRequest request,HttpServletResponse response, String token, String appId ){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
		List<PreIncomeVo> itemlist = new ArrayList<PreIncomeVo>();
	    try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			//只有云店主展示预估收益
    			if(usersMall.getType().equals("002")){
    				itemlist = getPreDetail(userId,"001");// 预估标识（001：预估，002：实际）
    				resultMap.put(DATA, itemlist);
    				errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
    			}
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "mypreincomelog", e.toString(),"预估收益明细",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	
	/**
	 * 根据时间段获取预估收益明细
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/getpreincomelogByTime")
	@ResponseBody
	public Map<String,Object> getpreincomelogByTime( HttpServletRequest request,HttpServletResponse response, String token, String appId ){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
		List<PreIncomeVo> itemlist = new ArrayList<PreIncomeVo>();
	    try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			//只有云店主展示预估收益
    			if(usersMall.getType().equals("002")){
    				itemlist = getPreDetail(userId,"001");// 预估标识（001：预估，002：实际）
    				resultMap.put(DATA, itemlist);
    				errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
    			}
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getpreincomelogByTime", e.toString(),"根据时间段获取预估收益明细",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	
	
	/**
	 * 累计收益明细
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/myactualincomelog")
	@ResponseBody
	public Map<String,Object> myactualincomelog( HttpServletRequest request,HttpServletResponse response, String token, String appId ){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
		List<PreIncomeVo> itemlist = new ArrayList<PreIncomeVo>();
	    try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			String userId = usersMall.getId();
    			//只有云店主展示预估收益
    			if(usersMall.getType().equals("002")){
    				itemlist = getPreDetail(userId,"002");// 预估标识（001：预估，002：实际）
    				resultMap.put(DATA, itemlist);
    				errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
    			}
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "myactualincomelog", e.toString(),"累计收益明细",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	
	/**
	 * 购物车数量调节
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param goodsId
	 * @param count
	 * @return
	 */
	@RequestMapping(value="/adjustshoppingcartCount")
	@ResponseBody
	public Map<String,Object> adjustshoppingcartCount( HttpServletRequest request,HttpServletResponse response, String token, String appId ,String goodsId,int count){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    	if(usersMall != null){
	    		String userId = usersMall.getId();
	    		UsersShoppingCartItem item = getShoppingCartItem(userId,goodsId);
	    		if(item != null){
	    			item.setCount(count);
	    			String result = usersShoppingCartItemService.edit(item);
	    			if(SUCCESS.equals(result)){
	    				errorCode = SUCCESS_ERROR_CODE;
						errorMsg = SUCCESS_ERROR_MSG;
	    			}
	    		}else{
	    			errorCode = SHOPPING_CART_ITEM_ERROR_CODE;
	    			errorMsg = SHOPPING_CART_ITEM_ERROR_MSG;
	    		}
	    	}else{
	    		errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "adjustshoppingcartCount", e.toString(),"购物车数量",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	/**
	 * 删除购物车
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param cartId
	 * @return
	 */
	@RequestMapping(value="/delshoppingcart")
	@ResponseBody
	public Map<String,Object> delshoppingcart( HttpServletRequest request,HttpServletResponse response, String token, String appId ,String cartId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	String result = null;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    	if(usersMall != null){
	    		String userId = usersMall.getId();
	    		String[] cartIds = cartId.split(",");
	    		for(int i=0;i<cartIds.length;i++){
	    			UsersShoppingCartExample examplec = new UsersShoppingCartExample();
		    		com.itic.mall.system.users.shoppingcart.persistence.model.UsersShoppingCartExample.Criteria criteriac = examplec.createCriteria();
		    		criteriac.andIsEffectiveEqualTo(DBConst.TRUE);
		    		criteriac.andCartIdEqualTo(cartIds[i]);
		    		criteriac.andUserIdEqualTo(userId);
		    		List<UsersShoppingCart> listc = usersShoppingCartService.list(examplec);
		    		if(listc.size()>0){
		    			UsersShoppingCart usersShoppingCart = listc.get(0);
		    			result = usersShoppingCartService.delete(usersShoppingCart);
		    			if(SUCCESS.equals(result)){
		    				UsersShoppingCartItemExample example = new UsersShoppingCartItemExample();
							com.itic.mall.system.users.shoppingcartitem.persistence.model.UsersShoppingCartItemExample.Criteria criteria = example.createCriteria();
							criteria.andIsEffectiveEqualTo(DBConst.TRUE);
							criteria.andCartIdEqualTo(cartIds[i]);
							criteria.andUserIdEqualTo(userId);
			    			List<UsersShoppingCartItem> list = usersShoppingCartItemService.list(example);
			    			if(list.size()>0){
			    				UsersShoppingCartItem CartItem = list.get(0);
			    				result = usersShoppingCartItemService.delete(CartItem);
			    				if(SUCCESS.equals(result)){
			    					errorCode = SUCCESS_ERROR_CODE;
									errorMsg = SUCCESS_ERROR_MSG;
			    				}
			    			}else{
				    			errorCode = SHOPPING_CART_ITEM_ERROR_CODE;
				    			errorMsg = SHOPPING_CART_ITEM_ERROR_MSG;
				    			break;
				    		}
		    			}
		    		}else{
		    			errorCode = SHOPPING_CART_ERROR_CODE;
		    			errorMsg = SHOPPING_CART_ERROR_MSG;
		    			break;
		    		}
	    		}
	    		
	    	}else{
	    		errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "delshoppingcart", e.toString(),"删除购物车",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	    }
	/**
	 * 添加购物车
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/addshoppingcart")
	@ResponseBody
	public Map<String,Object> addshoppingcart( HttpServletRequest request,HttpServletResponse response, String token, String appId ,String skuId,int count){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	String cartId = null;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	String addresult = null;
	    	UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    	if(usersMall != null){
	    		String userId = usersMall.getId();
	    		//添加购物车之前判断该商品在用户购物车中是否存在，存在则直接对数量进行加的操作
	    		UsersShoppingCartItem item = getShoppingCartItem(userId,skuId);
	    		if(item != null){
	    			addresult = addShoppingCart(userId,skuId,count);
	    			if(SUCCESS.equals(addresult)){
	    				errorCode = SUCCESS_ERROR_CODE;
						errorMsg = SUCCESS_ERROR_MSG;
	    			}
	    		}else{
	    			UsersShoppingCart usersShoppingCart = new UsersShoppingCart();
		    		cartId = IdGen.uuid();
		    		usersShoppingCart.setCartId(cartId);
		    		usersShoppingCart.setUserId(userId);
		    		addresult =usersShoppingCartService.add(usersShoppingCart);
		    		if(SUCCESS.equals(addresult)){
		    			//获取商品信息
		    			GoodsDetailVo goodsDetailVo = this.goodsSkuService.getSkuDetailBySkuId(skuId, count);
		    			//GoodsDetailVo goodsDetailVo = getGoodsDetailBySkuId(skuId,count);
		    			UsersShoppingCartItem usersShoppingCartItem = new UsersShoppingCartItem();
		    			usersShoppingCartItem.setUserId(userId);
		    			usersShoppingCartItem.setGoodsId(skuId);
		    			usersShoppingCartItem.setGoodsImg(goodsDetailVo.getGoodsImg());
		    			usersShoppingCartItem.setGoodsName(goodsDetailVo.getGoodsName());
		    			usersShoppingCartItem.setOrginPrice(goodsDetailVo.getOrginPrice());
		    			usersShoppingCartItem.setPrice(goodsDetailVo.getPrice());
		    			usersShoppingCartItem.setCount(count);
		    			//获取商品券信息
		    			GoodsCoupon goodsCoupon = getCouponDetailByGoodsId(skuId);
		    			usersShoppingCartItem.setCouponId(goodsCoupon.getCouponId());
		    			usersShoppingCartItem.setCouponAmount(goodsCoupon.getAmount());
		    			usersShoppingCartItem.setCartId(cartId);
		    			addresult = usersShoppingCartItemService.add(usersShoppingCartItem);
		    			if(SUCCESS.equals(addresult)){
		    				errorCode = SUCCESS_ERROR_CODE;
							errorMsg = SUCCESS_ERROR_MSG;
		    			}
		    		}
	    		}
	    	}else{
	    		errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "addshoppingcart", e.toString(),"添加购物车",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	    }
	/**
	 * 添加收藏
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param goodsId
	 * @param count
	 * @return
	 */
	@RequestMapping(value="/addcollect")
	@ResponseBody
	public Map<String,Object> addcollect( HttpServletRequest request,HttpServletResponse response, String token, String appId ,String goodsId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    String result = FAIL;
	    try{
	    	UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    	if(usersMall != null){
	    		String userId = usersMall.getId();
	    		if(StringHelper.isNotBlank(goodsId)){
	    			String goodsIds[] = goodsId.split(",");
	    			for(String id:goodsIds){
	    				//根据商品ID取商品优惠券
		    			SkuCoupon skuCoupon= this.skuCouponService.getSkuCouponByGoodId(id);
		    			double couponAmount = 0;
		    			if(skuCoupon!=null)
		    				couponAmount = skuCoupon.getMoney()==null?0:skuCoupon.getMoney();
						GoodsSpu goodsSpu = getgoodsDetailSale(id);
		    			UsersCollect usersCollect = new UsersCollect();
		    			UsersCollectItem usersCollectItem = new UsersCollectItem();
		    			usersCollect.setUserId(userId);
		    			usersCollect.setGoodsId(id);
		    			usersCollectItem.setCouponAmount(couponAmount);
		    			usersCollectItem.setGoodsId(id);
		    			usersCollectItem.setGoodsImg(goodsSpu.getMainImageUrl());
		    			usersCollectItem.setGoodsName(goodsSpu.getGoodsName());
		    			usersCollectItem.setOrginPrice(goodsSpu.getPrice());
		    			usersCollectItem.setPrice(goodsSpu.getConPrice());
		    			usersCollectItem.setTotalFeedback(goodsSpu.getTotalFeedback());
		    			usersCollectItem.setTotalSales(goodsSpu.getTotalSales());
		    			usersCollectItem.setUserId(userId);
		    			result = usersCollectService.add(usersCollect);
		    			if(SUCCESS.equals(result)){
		    				result = usersCollectItemService.add(usersCollectItem);
		    				if(SUCCESS.equalsIgnoreCase(result)){
		    					errorCode = SUCCESS_ERROR_CODE;
		    					errorMsg = SUCCESS_ERROR_MSG;
		    				}
		    			}	    			
	    			}
	    		}
	    	}else{
	    		errorCode = LOGIN_ERROR_CODE; 
		       	errorMsg = LOGIN_ERROR_MSG;
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "addcollect", e.toString(),"添加收藏",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	    }
	/**
	 * 我的收藏列表展示
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param goodsId
	 * @return
	 */
	@RequestMapping(value="/mycollectlist")
	@ResponseBody
	public Map<String,Object> mycollectlist( HttpServletRequest request,HttpServletResponse response, String token, String appId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	List<UsersCollectVo> collectlist = new ArrayList<UsersCollectVo>();
	    	UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    	if(usersMall != null){
	    		String userId = usersMall.getId();
	    		UsersCollectItemExample example = new UsersCollectItemExample();
	    		com.itic.mall.system.users.collectionitem.persistence.model.UsersCollectItemExample.Criteria criteria = example.createCriteria();
	    		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
	    		criteria.andUserIdEqualTo(userId);
	    		List<UsersCollectItem> list = usersCollectItemService.list(example);
	    		this.handlePageQueryDefault(request, example);
	    		Map<String, Object> dataMap = new HashMap<>();
	    		dataMap.put("total", list.size());
	    		String isMore = isMore(request, list.size());
	    		dataMap.put("isMore",isMore);
	    		list =this.usersCollectItemService.list(example);
	    		if(list.size()>0){
	    			for(UsersCollectItem usersCollectItem:list){
	    				//根据商品ID获取商品图片，商品标题，商品原始价格，商品出售价格，商品总销量和总评论数，商品优惠券
	    				UsersCollectVo usersCollectVo = new UsersCollectVo();
	    				usersCollectVo.setSpuPlatform("yh");
	    				usersCollectVo.setId(usersCollectItem.getGoodsId());
	    				String fee = String.valueOf(usersCollectItem.getCouponAmount());
	    				if(fee != "null"){
		    				usersCollectVo.setCouponAmount(usersCollectItem.getCouponAmount());
	    				}
	    				usersCollectVo.setGoodsImg(usersCollectItem.getGoodsImg());
	    				usersCollectVo.setGoodsName(usersCollectItem.getGoodsName());
	    				String marketProfit = String.valueOf(usersCollectItem.getMarketProfit());
	    				if(marketProfit != "null"){
		    				usersCollectVo.setMarketProfit(usersCollectItem.getMarketProfit());
	    				}
	    				String originPrice = String.valueOf(usersCollectItem.getOrginPrice());
	    				if(originPrice != "null"){
		    				usersCollectVo.setOriginPrice(usersCollectItem.getOrginPrice());
	    				}
	    				String price = String.valueOf(usersCollectItem.getPrice());
	    				if(price != "null"){
		    				usersCollectVo.setPrice(usersCollectItem.getPrice());
	    				}
	    				String totalFeedback = String.valueOf(usersCollectItem.getTotalFeedback());
	    				if(totalFeedback != "null"){
		    				usersCollectVo.setTotalFeedback(usersCollectItem.getTotalFeedback());
	    				}
	    				String totalSale = String.valueOf(usersCollectItem.getTotalSales());
	    				if(totalSale != "null"){
		    				usersCollectVo.setTotalSale(usersCollectItem.getTotalSales());
	    				}
	    				collectlist.add(usersCollectVo);
	    			}
	    		}
	    		dataMap.put("list", collectlist);
	    		errorCode = SUCCESS_ERROR_CODE;
	    		errorMsg = SUCCESS_ERROR_MSG;
	    		resultMap.put(DATA, dataMap);
	    		
	    	}else{
	    		errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
	    	}
	    	
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "mycollectlist", e.toString(),"我的收藏列表展示",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	    }
	/**
	 * 添加店铺收藏
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param storeId
	 * @return
	 */
	@RequestMapping(value="/addstorecollect")
	@ResponseBody
	public Map<String,Object> addstorecollect( HttpServletRequest request,HttpServletResponse response, String token,String appId, String storeId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    String result = FAIL;
	   	try{
	    	UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    	if(usersMall != null){
	    		String userId = usersMall.getId();
	    		if(StringHelper.isNotBlank(storeId)){	    			
	    			UsersCollect usersCollect = new UsersCollect();
	    			UsersCollectItem usersCollectItem = new UsersCollectItem();
	    			usersCollect.setUserId(userId);
	    			usersCollect.setStoreId(storeId);
	    			//根据店铺ID获取店铺信息
	    			StoreVo storeVo = getStoreDetail(storeId);
	    			usersCollectItem.setStoreId(storeId);
	    			usersCollectItem.setStoreImg(storeVo.getImg());
	    			usersCollectItem.setStoreName(storeVo.getStoreName());
	    			usersCollectItem.setUserId(userId);
	    			result = usersCollectService.add(usersCollect);
	    			if(SUCCESS.equals(result)){
		    			result = usersCollectItemService.add(usersCollectItem);
		    			if(SUCCESS.equalsIgnoreCase(result)){
		    				errorCode = SUCCESS_ERROR_CODE;
							errorMsg = SUCCESS_ERROR_MSG;
		    			}
	    			}	    			
	    		}
	    	}else{
	    		errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
	    	}	    
	   	}catch(Exception e){
	   		errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "addstorecollect", e.toString(),"添加店铺收藏",e);
	   	}
	   	resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	   	}
	/**
	 * 我的店铺收藏列表
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param storeId
	 * @return
	 */
	@RequestMapping(value="/mystorecollectlist")
	@ResponseBody
	public Map<String,Object> mystorecollectlist( HttpServletRequest request,HttpServletResponse response, String token,String appId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	List<StoreVo> storelist = new ArrayList<StoreVo>();
	    	UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    	if(usersMall != null){
	    		String userId = usersMall.getId();
	    		UsersCollectItemExample example = new UsersCollectItemExample();
	    		com.itic.mall.system.users.collectionitem.persistence.model.UsersCollectItemExample.Criteria criteria = example.createCriteria();
	    		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
	    		criteria.andUserIdEqualTo(userId);
	    		criteria.andStoreIdIsNotNull();
				List<UsersCollectItem> list = usersCollectItemService.list(example);
				if (list.size() > 0) {
					for (UsersCollectItem usersCollectItem : list) {
						StoreVo storeVo = new StoreVo();
						storeVo.setId(usersCollectItem.getId());
						storeVo.setImg(usersCollectItem.getStoreImg());
						storeVo.setStoreId(usersCollectItem.getStoreId());
						storeVo.setStoreName(usersCollectItem.getStoreName());
						storelist.add(storeVo);
					}
				}
				resultMap.put(DATA, storelist);
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			} else {
				errorCode = LOGIN_ERROR_CODE;
				errorMsg = LOGIN_ERROR_MSG;
			}
		} catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "mystorecollectlist", e.toString(),"我的店铺收藏列表",e);
	    }
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	    }
	/**
	 * 根据店铺ID获取店铺信息
	 * @param storeId
	 * @return
	 */
	public StoreVo getStoreDetail(String storeId){
		StoreVo storeVo = new StoreVo();
		if(StringHelper.isNotBlank(storeId)){
			GoodsStoreExample example = new GoodsStoreExample();
			com.itic.mall.system.goods.store.persistence.model.GoodsStoreExample.Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
			criteria.andIdEqualTo(storeId);
			List<GoodsStore> list = goodsStoreService.list(example);
			if(list.size()>0){
				storeVo.setStoreId(storeId);
				storeVo.setImg(list.get(0).getImg());
				storeVo.setStoreName(list.get(0).getStoreName());
			}
		}
		return storeVo;
	}
	/**
	 * 我的购物车
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/myshoppingcart")
	@ResponseBody
	public Map<String,Object> myshoppingcart( HttpServletRequest request,HttpServletResponse response, String token, String appId ){
		String errorCode = PARAM_ERROR_CODE;
 	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
		List<ShoppingCartVo> listMaps = new ArrayList<ShoppingCartVo>();
	    try{
	    	UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    	if(usersMall != null){
	    		String userId = usersMall.getId();
	    		UsersShoppingCartExample examplecart = new UsersShoppingCartExample();
	    		com.itic.mall.system.users.shoppingcart.persistence.model.UsersShoppingCartExample.Criteria criteriacart = examplecart.createCriteria();
	    		criteriacart.andIsEffectiveEqualTo(DBConst.TRUE);
	    		criteriacart.andUserIdEqualTo(userId);
	    		List<UsersShoppingCart> listcart = usersShoppingCartService.list(examplecart);
	    		if(listcart.size()>0){
	    			for(int i=0;i<listcart.size();i++){
	    				ShoppingCartVo Vo = new ShoppingCartVo();
	    				String cartId  = listcart.get(i).getCartId();
		    			UsersShoppingCartItemExample exampleus = new UsersShoppingCartItemExample();
		    			com.itic.mall.system.users.shoppingcartitem.persistence.model.UsersShoppingCartItemExample.Criteria criteriaus = exampleus.createCriteria();
		    			criteriaus.andIsEffectiveEqualTo(DBConst.TRUE);
		    			criteriaus.andCartIdEqualTo(cartId);
		    			List<UsersShoppingCartItem> listus = new ArrayList<UsersShoppingCartItem>();
		    			listus = usersShoppingCartItemService.list(exampleus);
		    			if(listus.size()>0){
		    				String goodsId = listus.get(0).getGoodsId();
		    				GoodsSpu goodsSpu = this.goodsSpuService.getBySku(goodsId);
		    				if(goodsSpu!=null)
		    					Vo.setId(goodsSpu.getId());
		    				Vo.setGoodsId(goodsId);
		    				Vo.setCartId(cartId);
							Vo.setActualpay(listus.get(0).getPrice());
							Vo.setOriginPrice(listus.get(0).getOrginPrice());
							Vo.setGoodsImg(listus.get(0).getGoodsImg());
							Vo.setGoodsName(listus.get(0).getGoodsName());
							GoodsSpu goodSpu = this.goodsSpuService.getBySku(goodsId);
							if(goodSpu!=null){
								SkuCoupon coupon = this.skuCouponService.getSkuCouponByGoodId(goodSpu.getId());
								if(coupon!=null){
									List<UsersCoupon> usersCoupons = this.usersCouponService.getUserCouponByUserIdAndCouponId(usersMall.getId(), coupon.getId());
									if(usersCoupons.isEmpty())
										Vo.setIsRevice("0");
									else
										Vo.setIsRevice("1");
									Vo.setCouponAmount(coupon.getMoney());
									
									Vo.setCouponId(coupon.getId());
								}
							}
		    				Vo.setCount(listus.get(0).getCount()==null?0:listus.get(0).getCount());
		    				Map<String, Object> paramMap = this.goodsSkuService.getGoodSkuById(goodsId);
							Vo.setParam(paramMap);
		    			}
		    			listMaps.add(Vo);
	    			}
	    		}
	    		resultMap.put(DATA, listMaps);
    			errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
	    	}else{
	    		errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
	    	}
	    	
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "myshoppingcart", e.toString(),"我的购物车",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	    }
	/**
	 * 个人信息展示
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/info")
	@ResponseBody
	public Map<String,Object> info( HttpServletRequest request,HttpServletResponse response,String token, String appId){
		Map<String,Object> resultMap = new HashMap<String,Object>();
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	try{
	   		String defaultHeadImg = sysSettingService.getByKey("DEFAULT_HEAD_IMAGE");
	   		if(StringHelper.isNotBlank(token) && StringHelper.isNotBlank(appId)){
	   			UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
		    	Map<String, Object> dataMap = new HashMap<String,Object>();
		   		if(usersMall != null){
		   			errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
					dataMap.put("userHeadimg", usersMall.getUserHeadImg()==null?defaultHeadImg:usersMall.getUserHeadImg());
					dataMap.put("userNickname", usersMall.getUserNickName()==null?"未指定":usersMall.getUserNickName());
					dataMap.put("birth", usersMall.getBirth()==null?"0000-00-00":usersMall.getBirth());
					dataMap.put("sex", usersMall.getSex()==null?"未指定":usersMall.getSex());
					dataMap.put("city", usersMall.getCity()==null?"未指定":usersMall.getCity());
	   				dataMap.put("phone", usersMall.getUserPhone());
	   				dataMap.put("tgwId", getPositionByUserId(usersMall.getId()));
					resultMap.put(DATA, dataMap);
		   		}else{
		   			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
		   		}
	   		}
	   	}catch(Exception e){
	   		errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "info", e.toString(),"个人信息展示",e);
	   	}
		isCrrossDomain(response);
	   	resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	/**
	 * 用户姓名编辑
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param userNickname
	 * @return
	 */
	@RequestMapping(value="/manageuserNickname")
	@ResponseBody
	public Map<String,Object> manageuserNickname(HttpServletRequest request,HttpServletResponse response,String token, String appId,String userNickname){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	String editresult = FAIL;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(token)&&StringHelper.isNotBlank(appId)){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
				if(usersMall != null){
					if (StringHelper.isNotBlank(userNickname)) {
						usersMall.setUserNickName(userNickname);
					}
				}else{
		   			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
		   		}
				editresult = usersMallService.edit(usersMall);
				if (editresult.equals(SUCCESS)) {
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "manage", e.toString(),"用户信息编辑",e);
	    }
		isCrrossDomain(response);
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	/**
	 * 用户头像编辑
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param userHeadImg
	 * @return
	 */
	@RequestMapping(value="/manageuserHeadImg")
	@ResponseBody
	public Map<String,Object> manageuserHeadImg(HttpServletRequest request,HttpServletResponse response,String token, String appId,String userHeadImg){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	String editresult = FAIL;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(token)&&StringHelper.isNotBlank(appId)){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
				if(usersMall != null){
					if (StringHelper.isNotBlank(userHeadImg)) {
						usersMall.setUserHeadImg(userHeadImg);
					}
				}else{
		   			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
		   		}
				editresult = usersMallService.edit(usersMall);
				if (editresult.equals(SUCCESS)) {
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "manageuserHeadImg", e.toString(),"用户头像编辑",e);
	    }
		isCrrossDomain(response);
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	/**
	 * 用户城市编辑
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param birth
	 * @return
	 */
	@RequestMapping(value="/managecity")
	@ResponseBody
	public Map<String,Object> managecity(HttpServletRequest request,HttpServletResponse response,String token, String appId,String city){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	String editresult = FAIL;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(token)&&StringHelper.isNotBlank(appId)){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
				if(usersMall != null){
					if (city != null) {
						usersMall.setCity(city);
					}
				}else{
		   			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
		   		}
				editresult = usersMallService.edit(usersMall);
				if (editresult.equals(SUCCESS)) {
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "managecity", e.toString(),"用户城市编辑",e);
	    }
		isCrrossDomain(response);
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
	    return resultMap;
	}
	/**
	 * 用户生日编辑
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param birth
	 * @return
	 */
	@RequestMapping(value="/managebirth")
	@ResponseBody
	public Map<String,Object> managebirth(HttpServletRequest request,HttpServletResponse response,String token, String appId,Date birth){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	String editresult = FAIL;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(token)&&StringHelper.isNotBlank(appId)){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
				if(usersMall != null){
					if (birth != null) {
						usersMall.setBirth(birth);
					}
				}else{
		   			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
		   		}
				editresult = usersMallService.edit(usersMall);
				if (editresult.equals(SUCCESS)) {
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "managebirth", e.toString(),"用户生日信息编辑",e);
	    }
		isCrrossDomain(response);
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
	    return resultMap;
	}
	/**
	 * 用户性别编辑
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param sex
	 * @return
	 */
	@RequestMapping(value="/managesex")
	@ResponseBody
	public Map<String,Object> managesex(HttpServletRequest request,HttpServletResponse response,String token, String appId,String sex){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	String editresult = FAIL;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(token)&&StringHelper.isNotBlank(appId)){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
				if(usersMall != null){
					if (sex != null) {
						usersMall.setSex(sex);
					}
				}else{
		   			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
		   		}
				editresult = usersMallService.edit(usersMall);
				if (editresult.equals(SUCCESS)) {
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "managebirth", e.toString(),"用户生日信息编辑",e);
	    }
		isCrrossDomain(response);
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
	    return resultMap;
	}
	/**
	 * 获取支付宝绑定信息
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/getAliInfo")
	@ResponseBody
	public Map<String,Object> getAliInfo(HttpServletRequest request,HttpServletResponse response,String token, String appId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(token) && StringHelper.isNotBlank(appId)){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    		if(usersMall != null){
	    			String aliId = usersMall.getAliId();
	    			String userRealName = usersMall.getUserRealName();
	    			UsersAliInfoVo usersAliInfoVo = new UsersAliInfoVo();
	    			usersAliInfoVo.setAliId(aliId);
	    			usersAliInfoVo.setUserRealName(userRealName);
	    			resultMap.put(DATA, usersAliInfoVo);
	    		}else{
	    			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
	    		}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getAliInfo", e.toString(),"获取支付宝绑定信息",e);
	    }
	    isCrrossDomain(response);
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
	    return resultMap;
	    }
	/**
	 * 绑定用户支付宝账户
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param aliId
	 * @param userRealName
	 * @return
	 */
	@RequestMapping(value="/editAliInfo")
	@ResponseBody
	public Map<String,Object> editAliInfo(HttpServletRequest request,HttpServletResponse response,String token, String appId,String aliId,String userRealName){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(token) && StringHelper.isNotBlank(appId) && StringHelper.isNotBlank(aliId) && StringHelper.isNotBlank(userRealName)){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    		if(usersMall != null){
	    			usersMall.setAliId(aliId);
	    			usersMall.setUserRealName(userRealName);
	    			String result = usersMallService.edit(usersMall);
	    			if(SUCCESS.equals(result)){
	    				errorCode = SUCCESS_ERROR_CODE;
	    				errorMsg = SUCCESS_ERROR_MSG;
	    			}
	    		}else{
	    			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
	    		}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getAliInfo", e.toString(),"编辑支付宝绑定信息",e);
	    }
	    isCrrossDomain(response);
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
	    return resultMap;
	    }
	
	/**
	 * 获取用户微信号
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @return
	 */
	@RequestMapping(value="/getuinionid")
	@ResponseBody
	public Map<String,Object> getuinionid(HttpServletRequest request,HttpServletResponse response,String token, String appId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			resultMap.put("uinionid", usersMall.getUnionid());
    			errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
    		}else{
	   			errorCode = LOGIN_ERROR_CODE;
	   			errorMsg = LOGIN_ERROR_MSG;
	   		}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "managebirth", e.toString(),"获取用户微信号",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
	    return resultMap;
	    }
	/**
	 * 微信换绑接口
	 * @param id
	 * @param unionid
	 * @return
	 */
	@RequestMapping(value="/chguinionid")
	@ResponseBody
	public Map<String,Object> chguinionid(HttpServletRequest request,HttpServletResponse response,String token, String appId,String unionid){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	String editresult = FAIL;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(token) && StringHelper.isNotBlank(appId) && StringHelper.isNotBlank(unionid)){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
		   		if(usersMall != null){
			   		usersMall.setUnionid(unionid);
		   		}else{
		   			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
		   		}
				editresult = usersMallService.edit(usersMall);
				if(editresult.equals(SUCCESS)){
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "chguinionid", e.toString(),"换绑微信号",e);
	    }
		isCrrossDomain(response);
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
	    return resultMap;
	}
	
	@RequestMapping(value="/forgetpwd")
	@ResponseBody
	public Map<String,Object> forgetpwd(HttpServletRequest request,HttpServletResponse response,String phone,String code,String appId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(phone) && StringHelper.isNotBlank(code)){
	    		if(isEffectiveCode(phone,code)){
	   				UsersMall usersMall = getUsersByPhone(phone);
	   				if(usersMall != null){
	   					UsersToken usersToken = createToken(usersMall, appId);
	   					String result = usersTokenService.addAndSyncOther(usersToken);
	   					if(SUCCESS.equals(result)){
	   						resultMap.put("token", usersToken.getAccessToken());
	   						resultMap.put("appId", usersToken.getAppId());
	   						errorCode = SUCCESS_ERROR_CODE;
							errorMsg = SUCCESS_ERROR_MSG;
	   					}
	   				}else{
	   					errorCode = PHONE_NULL_ERROR_CODE;
	   					errorMsg = PHONE_NULL_ERROR_MSG;
	   				}
	    		}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "forgetpwd", e.toString(),"忘记密码接口",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	    }
	
	/**
     * 验证码是否有效
     * @param phone
     * @param code
     * @return
     */
    public boolean isEffectiveCode( String phone, String code ){
    	boolean result = false;
    	UsersCodeExample example = new UsersCodeExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andCodeEqualTo(code);
    	criteria.andPhoneEqualTo(phone);
    	criteria.andExpiredTimeGreaterThanOrEqualTo(new Date());
    	
    	List<UsersCode> list = usersCodeService.list(example);
    	if( list.size() > 0 ){
    		result = true;
    	}
    	return result;
    }
	/**
	 * 重置密码
	 * @param request
	 * @param response
	 * @param token
	 * @param appId
	 * @param newpwd
	 * @param confirmpwd
	 * @return
	 */
	@RequestMapping(value="/chgpwd")
	@ResponseBody
	public Map<String,Object> chgpwd(HttpServletRequest request,HttpServletResponse response,String token, String appId,String newpwd,String confirmpwd){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	String editresult = FAIL;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringHelper.isNotBlank(newpwd) && StringHelper.isNotBlank(confirmpwd)){
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
		   		if(usersMall != null ){
		   			if( newpwd.equals(confirmpwd)){
				   		usersMall.setUserPwd(newpwd);
		   			}else{
		   				errorCode = PWD_CONFIRM_ERROR_CODE;
		   				errorMsg = PWD_CONFIRM_ERROR_MSG;
		   			}
		   			editresult = usersMallService.edit(usersMall);
					if(editresult.equals(SUCCESS)){
						errorCode = SUCCESS_ERROR_CODE;
						errorMsg = SUCCESS_ERROR_MSG;
					}
		   		}else{
		   			errorCode = LOGIN_ERROR_CODE;
		   			errorMsg = LOGIN_ERROR_MSG;
		   		}
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "chgpwd", e.toString(),"修改用户密码",e);
	    }
		isCrrossDomain(response);
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
	    return resultMap;
	}
	
	@RequestMapping(value="preDetail")
	@ResponseBody
	public Map<String, Object> getUserPreDetail(HttpServletRequest request,HttpServletResponse response,String token, String appId,String preType,String orderNo,String startTime,String endTime) {
		String errorCode = SUCCESS_ERROR_CODE;
		String errorMsg = SUCCESS_ERROR_MSG;
		Map<String, Object> resultMap = new HashMap<String,Object>();
		PreType type =null;
		if(StringUtils.isNoneBlank(token,appId,preType)&&(type = PreType.getPreType(preType))!=null) {
			try{
				UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
				if(usersMall != null) { 
					String userId = usersMall.getId();
					List<PreIncomeVo> itemlist = new ArrayList<PreIncomeVo>();
					//根据条件获取PayLog
					PayUserlogExample example = new PayUserlogExample();
					this.handlePageQueryDefault(request, example);
					List<PayUserlog> list = payUserlogService.findPayUserLogBycondition(example,userId, type, orderNo, startTime, endTime);
 					int count = payUserlogService.count(example);// 总条数
					if (!list.isEmpty()) {
						for (PayUserlog payUserlog : list) {
							PreIncomeVo preIncomeVo = this.payUserlogWrapPreIncomeVo(payUserlog);
							itemlist.add(preIncomeVo);
						}
					}
					Map<String, Object> dataMap
					= new HashMap<>();
					dataMap.put("list", itemlist);
					dataMap.put("total", count);
					resultMap.put(DATA, dataMap);
				}else {
					errorCode = LOGIN_ERROR_CODE;
					errorMsg = LOGIN_ERROR_MSG;
				}
			}catch(Exception e){
				errorCode = SERVER_ERROR_CODE;
				errorMsg = SERVER_ERROR_MSG;
				e.printStackTrace();
				//logException("UserdataInterface", "preDetail", e.toString(),"预估收益和累计收益",e);
			}
		}else {
			errorCode = PARAM_ERROR_CODE;
			errorMsg = PARAM_ERROR_MSG;
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	@RequestMapping(value="team/list")
	@ResponseBody
	public Map<String, Object> teamList(Integer start,Integer length,HttpServletRequest request,HttpServletResponse response,String token,String appId,String level,String startTime,String endTime,String userName,String userPhone,String field,String sort){
		String errorCode = SUCCESS_ERROR_CODE;
		String errorMsg = SUCCESS_ERROR_MSG;
		Map<String, Object> resultMap = new HashMap<>();
		TeamLevel teamLevel =  null;
		if(StringUtils.isNoneBlank(token,appId,level)&&(teamLevel = TeamLevel.getTeamLevel(level))!=null) {
			try{
				UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
				if(usersMall != null) {
					Condition condition = new Condition();
					condition.setParentId(usersMall.getId());
					condition.setLevel(teamLevel.getLevel());
					UsersMallExample example = new UsersMallExample();
					/*Page page = new Page();
			        String recordNow = this.getCleanParams(request, IticConst.RECORD_NOW);
			        if (StringHelper.isNotEmpty(recordNow)) {
			            recordNow=NumberStringHelper.mulString(recordNow, "10");
			            page.setRecordNow(Integer.parseInt(recordNow));
			            page.setPageSize(Integer.parseInt("10"));
			        }
			        example.setPage(page);*/
					this.handlePageQueryDefault(request, example);
					condition.setStart(example.getPage().getRecordNow());
					condition.setLength(example.getPage().getPageSize());
					condition.setEndDate(DateHelper.parseDate(endTime));
					condition.setStartDate(DateHelper.parseDate(startTime));
					condition.setNickName(userName);
					condition.setPhone(userPhone);
					condition.setField(field);
					condition.setSort(sort);
					Map<String, Object> dataMap = new HashMap<>();
					List<UsersMall> list = this.usersMallService.getTeamByLevel(condition);
					int count = this.usersMallService.getCountByLevel(condition);
					List<TeamOneVo> teamList = new ArrayList<TeamOneVo>();
					if(!list.isEmpty()){
						for(UsersMall user:list){
							TeamOneVo teamOneVo = this.usersMallWrapTeamOneVo(user);
							teamList.add(teamOneVo);
						} 
					}
					dataMap.put("list", teamList);
					dataMap.put("total", count);
					resultMap.put(DATA, dataMap);
				}else {
					errorCode = LOGIN_ERROR_CODE;
					errorMsg = LOGIN_ERROR_MSG;
				}
			}catch(Exception e){
				errorCode = SERVER_ERROR_CODE;
				errorMsg = SERVER_ERROR_MSG;
				
				logException("UserdataInterface", "team/list", e.toString(),"获取我的团队",e);
			}
		}else {
			errorCode = PARAM_ERROR_CODE;
			errorMsg = PARAM_ERROR_MSG;
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
	    isCrrossDomain(response);
		return resultMap;
	}
	private TeamOneVo usersMallWrapTeamOneVo(UsersMall user) {
		TeamOneVo teamOneVo = new TeamOneVo();
		teamOneVo.setUserId(user.getId());
		teamOneVo.setCreatTime(user.getCreateTime());
		//根据一级成员ID查询该成员下的下级
		///int teamNum = getTeamNum(user.getId());
		
		teamOneVo.setUserName(user.getUserNickName());
		UsersMall um = this.usersMallService.get(user.getParentId());
		if(um!=null)
			teamOneVo.setInviteName(um.getUserNickName());
		StoreInfo storeInfo = this.storeInfoService.findStoreInfoByUserId(user.getId());
		if(storeInfo !=null) {
			double totalSale = storeInfo.getTotalSale()==null?0:storeInfo.getTotalSale();
			teamOneVo.setTotalSale(totalSale);
			Condition condition = new Condition();
			condition.setLevel(TeamLevel.One.getLevel());
			condition.setParentId(user.getId());
			int myteamOne = this.usersMallService.getCountByLevel(condition);
			condition.setLevel(TeamLevel.Two.getLevel());
			int myteamTwo = this.usersMallService.getCountByLevel(condition);
			int teamNum = myteamOne + myteamTwo;
			teamOneVo.setTeamNum(teamNum);
		}
		teamOneVo.setUserPhone(user.getUserPhone());
		return teamOneVo;
	}
	
	private PreIncomeVo payUserlogWrapPreIncomeVo(PayUserlog payUserlog) {
		PreIncomeVo preIncomeVo = new PreIncomeVo();
		//预估收益类型（PI001：佣金，PI002：提成）
		String preIncomeType = payUserlog.getPreIncomeType();
		String preIncomeChannel = payUserlog.getPreIncomeChannel();
		//收入来源
		String source = getNameByType(preIncomeType);
		//收入渠道
		String channel = getNameByType(preIncomeChannel);
		
		preIncomeVo.setPreIncomename(channel);
		preIncomeVo.setPreTypename(source);
		// 订单号
		String goodsId = payUserlog.getSkuId();
		preIncomeVo.setOrderNo(payUserlog.getOrderNo());
		preIncomeVo.setOrderTime(payUserlog.getCreateTime());
		preIncomeVo.setOperate(payUserlog.getPreOperateType());
		// 根据订单号取下单人姓名
		PreIncomeChannel incomeChannel = PreIncomeChannel.getType(preIncomeChannel);
		switch (incomeChannel) {
		case jd:
			String orderJDId = "";
			PreType preType = PreType.getPreType(payUserlog.getPreType());
			switch (preType) {
			case pre:
				OrderJDLeadInto orderJDLeadInto = this.orderJDLeadIntoService.getOrderJDLeadIntoByOrderNum(payUserlog.getOrderNo());
				if(orderJDLeadInto!=null) {
					preIncomeVo.setActualPay(Double.parseDouble(orderJDLeadInto.getOrderTotalMoney()));
					UsersMall usersMall = this.usersMallService.get(orderJDLeadInto.getYunUserId());
					if(usersMall!=null)
						preIncomeVo.setUserNickName(usersMall.getUserNickName());
					orderJDId = orderJDLeadInto.getId();
				}
				break;
			case actual:
				OrderJD orderJD = this.ordersJDService.getOrderJDByOrderNum(payUserlog.getOrderNo());
				if(orderJD!=null) {
					preIncomeVo.setActualPay(Double.parseDouble(orderJD.getOrderTotalMoney()));
					UsersMall usersMall = this.usersMallService.get(orderJD.getYunUserId());
					if(usersMall!=null)
						preIncomeVo.setUserNickName(usersMall.getUserNickName());
					orderJDId = orderJD.getId();
				}
				break;
			}
			if(orderJDId.length()>0) {
				OrdersJDProduct ordersJDProduct = this.ordersJDProductService.getOrdersJDProjectByOrdersJDId(orderJDId);
				if(ordersJDProduct!=null) 
					preIncomeVo.setGoodsName(ordersJDProduct.getSkuName());
			}
			break;
		case yh:
			String userNickName = getUserNameByOrderNo(payUserlog.getOrderNo());
			preIncomeVo.setUserNickName(userNickName);
			// 订单项信息
			OrdersItemExample exampleitem = new OrdersItemExample();
			com.itic.mall.system.orders.item.persistence.model.OrdersItemExample.Criteria criteriao = exampleitem
					.createCriteria();
			criteriao.andIsEffectiveEqualTo(DBConst.TRUE);
			criteriao.andOrderNoEqualTo(payUserlog.getOrderNo());
			criteriao.andSkuIdEqualTo(payUserlog.getSkuId());
			List<OrdersItem> listo = ordersItemService.list(exampleitem);
			if (!listo.isEmpty()) {
				// 根据订单号获取订单项下所有购买商品，每一个订单项作为一条记录，获取商品名称，购买用户名称，实付金额
				preIncomeVo.setActualPay(listo.get(0).getPrice());
				preIncomeVo.setGoodsName(listo.get(0).getGoodsName());
			}
			break;
		}
	/*	UsersMall usersMall = this.usersMallService.get(payUserlog.getUserId());
		if(usersMall!=null)
			preIncomeVo.setUserNickName(usersMall.getUserNickName()+"分享");
*/
		//根据商品号获取该商品的佣金
		preIncomeVo.setProfitAmount(payUserlog.getPreAmount());
		return preIncomeVo;
	}
	
	private YunUserVo usersMallWrapYunUserVo(UsersMall usersMall) {
		String userId = usersMall.getId();
		YunUserVo yunUserVo = new YunUserVo();
		//店铺背景图片
		StoreInfo storeInfo = this.storeInfoService.findStoreInfoByUserId(usersMall.getId());
		if(storeInfo !=null) {
		
			yunUserVo.setUserImg(storeInfo.getStoreImg());
			yunUserVo.setUserNickName(storeInfo.getStoreName());
			yunUserVo.setBackGroundImg(storeInfo.getBackgoundImg());
			yunUserVo.setInviteCode(usersMall.getInvitingCode());
		}else {
			yunUserVo.setUserImg(usersMall.getUserHeadImg());
			yunUserVo.setUserNickName(usersMall.getUserNickName());
		}
		//订单数量
		int orderNum = getOrderNum(userId);
		//一级团队人数
		int myteamOne = usersMall.getSuccessPeopleOne()==null?0:usersMall.getSuccessPeopleOne();
		//二级团队人数
		int myteamTwo = usersMall.getSuccessPeopleTwo()==null?0:usersMall.getSuccessPeopleTwo();
		//团队总人数
		int myteamNum = myteamOne + myteamTwo;
		//总收益
		yunUserVo.setActualProfit(usersMall.getTotalProfit()==null?0:usersMall.getTotalProfit());
		//预计收益数量
		int preProfitNum = getPreOrActualNum(userId,"001");
		//累计收益数量
		int actualProfitNum = getPreOrActualNum(userId,"002");
		yunUserVo.setActualProfitNum(actualProfitNum);
		double money = usersMall.getMoney()==null? 0:usersMall.getMoney();
		//余额
		yunUserVo.setBalcance(money);
		yunUserVo.setMyteamNum(myteamNum);
		yunUserVo.setOrderNum(orderNum);
		yunUserVo.setPreProfit(usersMall.getPreProfit()==null?0:usersMall.getPreProfit());
		yunUserVo.setPreProfitNum(preProfitNum);
		
		return yunUserVo;
	}
	@RequestMapping(value="totalAmounct")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> getTotalReflectAcount(HttpServletRequest request,HttpServletResponse response,String token, String appId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	Map<String, Object> resultMap = new HashMap<String,Object>();
	   	Map<String, Object> data = new HashMap<>();
	   	try {
	   		UsersMall usersMall = this.CurUsersMall(request);
	   		double totalAmount =this.payUserlogService.getTotalAmount(usersMall.getId());
	   		data.put("totalAmount", totalAmount);
	   		resultMap.put(DATA, data);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "totalAmounct", e.toString(),"提现总额",e);
		}
	   	resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
		
	}
	
	@RequestMapping(value="pay/detail")
	@ResponseBody
	public Map<String, Object> userPayLogDetail(HttpServletRequest request,HttpServletResponse response,String token, String appId,String type) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	FinanceType financeType ;
	   	Map<String, Object> resultMap = new HashMap<String,Object>();
	   	if(StringUtils.isNotEmpty(type) && (financeType = FinanceType.getType(type))!=null) {
		    try{
	    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
	    		List<WithdrawVo> drawList = new ArrayList<WithdrawVo>();
	    		if(usersMall != null){
	    			Map<String, Object> dataMap = new HashMap<>();
	    			PayUserlogExample example = new PayUserlogExample();
	    			com.itic.mall.system.pay.userlog.persistence.model.PayUserlogExample.Criteria criteria = example.createCriteria();
	    			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
	    			criteria.andTypeEqualTo(financeType.getType());
	    			criteria.andUserIdEqualTo(usersMall.getId());
	    			example.setOrderByClause("create_time desc");
	    			this.handlePageQueryDefault(request, example);
	    			List<PayUserlog> list = payUserlogService.list(example);
	    			int count = payUserlogService.count(example);
	    			//double totalAmount = 0;
	    			if(!list.isEmpty()){
	    				for(PayUserlog payUserlog:list){
	    					WithdrawVo withdrawVo = new WithdrawVo();
	    					//多少钱
	    	    	    	withdrawVo.setAmount(payUserlog.getAmount());
	    	    	    	withdrawVo.setTime(payUserlog.getCreateTime());
	    					switch (financeType) {
							case Income:
								//InComeType inComeType = InComeType.getType(payUserlog.getIncomeType());
								//withdrawVo.setRemindMsg(inComeType.getName());
								break;
							case Pay:
								//TODO 消费信息
								break;
							case Reflect:
								//提现失败原因
		    	    	    	withdrawVo.setFailReason(payUserlog.getWithdrawFailReason());
		    	    	    	//手续费
		    	    	    	double free = payUserlog.getWithdrawFee()==null?0:payUserlog.getWithdrawFee();
		    	    	    	withdrawVo.setChargeFee(free);
		    	    	    	//失败成功信息
		        	    	    withdrawVo.setRemindMsg(payUserlog.getWithdrawRemind());
		        	    	    //时间
		        	    	    withdrawVo.setTime(payUserlog.getPayTime());
								break;
							default:
								break;
							}
	    	    	    	drawList.add(withdrawVo);
	    				}
	    			}
	    			dataMap.put("total", count);
	    			dataMap.put("withdrawList", drawList);
	    			resultMap.put(DATA, dataMap);
	    			errorCode = SUCCESS_ERROR_CODE;
	    			errorMsg = SUCCESS_ERROR_MSG;
	    		}else{
	    			errorCode = LOGIN_ERROR_CODE;
			       	errorMsg = LOGIN_ERROR_MSG;
	    		}
		    }catch(Exception e){
		    	errorCode = SERVER_ERROR_CODE;
		       	errorMsg = SERVER_ERROR_MSG;
		   		logException("UserdataInterface", "withdrawDetail", e.toString(),"提现明细",e);
		    }
	   	}else {
	   		errorCode = PARAM_ERROR_CODE;
		   	errorMsg = PARAM_ERROR_MSG;
	   	}
	    resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	@RequestMapping(value="recomGoods")
	@ResponseBody
	public Map<String, Object> getStoreRecomGoods(HttpServletRequest request,HttpServletResponse response,String token,String appId){
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try { 
    		UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
    		if(usersMall != null){
    			List<StoreGoodsVo> storeList = new ArrayList<StoreGoodsVo>();
    			Map<String, Object> dataMap = new HashMap<>();
    			String userId = usersMall.getId();
    			UsersStoreExample example = new UsersStoreExample();
    			com.itic.mall.system.users.store.persistence.model.UsersStoreExample.Criteria criteria = example.createCriteria();
    			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    			criteria.andUserIdEqualTo(userId);
    			criteria.andIsOwnerRecomEqualTo("1"); 
    			this.handlePageQueryDefault(request, example);
    			List<UsersStore> list = usersStoreService.list(example);
    			int count = usersStoreService.count(example);
    			String isMore = this.isMore(request, count);
    			if(list.size()>0){
    				for(UsersStore usersStore:list){
    					String goodsId = usersStore.getGoodsId();
    					StoreGoodsVo storeGoodsVo = getstoreGoods(userId,goodsId);
    					storeList.add(storeGoodsVo);
    				}
    			}
    			dataMap.put("list", storeList);
    			dataMap.put("total", count);
    			dataMap.put("isMore", isMore);
    			resultMap.put(DATA, dataMap);
    			errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
    		}else{
    			errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
    		}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserdataInterface", "getStoreRecomGoods", e.toString(),"获取店主推荐商品",e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	@RequestMapping(value="hostGoods")
	@ResponseBody
	public Map<String, Object> getStoreHotGoods(HttpServletRequest request,HttpServletResponse response,String token,String appId){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			UsersMall usersMall = getUsersByTokenAndAppId(token, appId);
			if(usersMall !=null) {
				Map<String, Object> dataMap = new HashMap<String, Object>();
				GoodsSpuExample example = new GoodsSpuExample();
				example.setOrderByClause("CREATE_TIME DESC");
				com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpuExample.Criteria
				criteria = example.createCriteria();
				criteria.andIsEffectiveEqualTo(DBConst.TRUE);// 是否有效
				criteria.andIsShowEqualTo(DBConst.TRUE);// 是否可见
				criteria.andIsHotEqualTo("1");
				this.handlePageQueryDefault(request, example);// 分页
				int count = goodsSpuService.count(example);// 总条数
				List<GoodsSpu> list = goodsSpuService.list(example);// 数据list
				List<StoreGoodsVo> storeGoodsVos = new ArrayList<>();
				if(!list.isEmpty()) {
					for(GoodsSpu goodsSpu :list ) {
						StoreGoodsVo storeGoodsVo = new StoreGoodsVo();		
						// 根据商品来源和商品ID封装商品信息
						// 根据商品ID获取优惠券金额
						double couponAmount = getCouponAmountByGoodsId(goodsSpu.getId());
						storeGoodsVo.setId(goodsSpu.getId());
						storeGoodsVo.setCouponMoney(goodsSpu.getCouponMoney());
						// 根据商品ID获取商品活动类型
						storeGoodsVo.setGoodsActive("003");
						storeGoodsVo.setMainImageUrl(goodsSpu.getMainImageUrl());
						storeGoodsVo.setGoodsName(goodsSpu.getGoodsName());
						// 在店铺表中获取是否以分享标志
						String isShared = getIsShared(goodsSpu.getSpuNum(), usersMall.getId());
						storeGoodsVo.setIsShared(isShared);
						storeGoodsVo.setWlCommission(goodsSpu.getWlCommission()==null?0:goodsSpu.getWlCommission());
						storeGoodsVo.setPrice(goodsSpu.getPrice()==null?0:goodsSpu.getPrice());
						storeGoodsVo.setConPrice(goodsSpu.getConPrice()==null?0:goodsSpu.getConPrice());
						// 根据商品来源获取条幅图片
						String resType = goodsSpu.getGoodsSource();
						String scrollImg = getScrollImg(resType);
						storeGoodsVo.setScrollImg(scrollImg);
						int feeback = goodsSpu.getTotalFeedback()==null?0:goodsSpu.getTotalFeedback();
						storeGoodsVo.setTotalFeedback(feeback);
						int totalSale = goodsSpu.getTotalSales()==null?0:goodsSpu.getTotalSales();
						storeGoodsVo.setTotalSales(totalSale);
						storeGoodsVo.setSpuPlatform(goodsSpu.getSpuPlatform());
						storeGoodsVos.add(storeGoodsVo);
					}
				}
				dataMap.put("total", count);
				dataMap.put("isMore", isMore(request, count));
				dataMap.put("list", storeGoodsVos);
				resultMap.put(DATA, dataMap);
				errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
			}else {
				errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UserdataInterface", "getStoreHotGoods", e.toString(), "店主的爆品商品", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	@RequestMapping(value="inviteRecord")
	@ResponseBody
	public Map<String, Object> inviteRecord(HttpServletRequest request,HttpServletResponse response,String token,String appId){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			UsersMall usersMall = getUsersByTokenAndAppId(token, appId);
			if(usersMall !=null) {
				UsersMallExample example = new UsersMallExample();
				this.handlePageQueryDefault(request, example);
				int start = example.getPage().getRecordNow();
				int length = example.getPage().getPageSize();
				List<UsersMall> usersMalls = this.usersMallService.getInviteRecordByUserID(usersMall.getId(), start, length);
				List<TeamOneVo> teamList = new ArrayList<TeamOneVo>();
				if(!usersMalls.isEmpty()) {
					for(UsersMall user:usersMalls) {
						TeamOneVo teamOneVo = this.usersMallWrapTeamOneVo(user);
						teamList.add(teamOneVo);
					}
				}
				int count = this.usersMallService.getInviteRecordCount(usersMall.getId());
				String isMore = this.isMore(request, count);
				Map<String , Object> dataMap = new HashMap<>();
				dataMap.put("toltal",count);
				dataMap.put("list", teamList);
				dataMap.put("isMore", isMore);
				resultMap.put(DATA, dataMap);
				errorCode = SUCCESS_ERROR_CODE;
    			errorMsg = SUCCESS_ERROR_MSG;
			}else {
				errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UserdataInterface", "inviteRecord", e.toString(), "用户邀请记录", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	@RequestMapping(value="editStore")
	@ResponseBody
	public Map<String , Object> editStore(HttpServletRequest request ,HttpServletResponse response,String token,String appId,String headImg,String name){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			UsersMall usersMall = getUsersByTokenAndAppId(token, appId);
			if(usersMall !=null) {
				StoreInfo storeInfo = this.storeInfoService.findStoreInfoByUserId(usersMall.getId());
				if(storeInfo !=null) {
					if(StringUtils.isNotEmpty(name))
						storeInfo.setStoreName(name);
					if(StringUtils.isNotEmpty(headImg)) 
						storeInfo.setStoreImg(headImg);
					boolean result = this.storeInfoService.editStoreInfo(storeInfo);
					if (result){
						errorCode = SUCCESS_ERROR_CODE;
						errorMsg = SUCCESS_ERROR_MSG;
					}
				}else {
					errorCode = Not_OPEND_YDZ_ERROR_CODE;
			       	errorMsg = Not_OPEND_YDZ_ERROR_MSG;
				}
			}else {
				errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UserdataInterface", "editStore", e.toString(), "修改店铺信息", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	@RequestMapping(value="balance")
	@ResponseBody
	public Map<String, Object> getUsersMallBalance(HttpServletRequest request ,HttpServletResponse response,String token,String appId){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			UsersMall usersMall = this.getUsersByTokenAndAppId(token, appId);
			if(usersMall!=null) {
				Map<String, Object> dataMap = new HashMap<>();
				double money = usersMall.getMoney()==null?0:usersMall.getMoney();
				dataMap.put("balance", money);
				resultMap.put(DATA, dataMap);
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			}else {
				errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UserdataInterface", "getUsersMallBalance", e.toString(), "查看用户余额接口", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	@RequestMapping(value="canceAdd")
	@ResponseBody
	public Map<String, Object> canceAdd(HttpServletResponse response,String token,String appId,String goodsId){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			UsersMall usersMall = this.getUsersByTokenAndAppId(token, appId);
			if(usersMall!=null) {
				UsersCollectItem usersCollectItem = this.usersCollectItemService.getCollectItemByUserIdAndGoodsId(usersMall.getId(), goodsId);
				this.usersCollectItemService.delete(usersCollectItem);
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			}else {
				errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UserdataInterface", "canceCollect", e.toString(), "取消收藏接口", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	@RequestMapping(value="canceCollect")
	@ResponseBody
	public Map<String, Object> canceCollect(HttpServletResponse response,String token,String appId,String id){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			UsersMall usersMall = this.getUsersByTokenAndAppId(token, appId);
			if(usersMall!=null) {
				UsersCollectItem usersCollectItem = this.usersCollectItemService.get(id);
				usersCollectItem.setIsEffective(DBConst.FALSE);
				this.usersCollectItemService.edit(usersCollectItem);
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			}else {
				errorCode = LOGIN_ERROR_CODE;
		       	errorMsg = LOGIN_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UserdataInterface", "canceCollect", e.toString(), "取消收藏接口", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	/**
	 * 根据用户id获得用户推广位id
	 * @param userId
	 * @return
	 */
	public String getPositionByUserId( String userId ){
		String tgwId = "";
		OpenStoreExample example = new OpenStoreExample();
		com.itic.mall.system.users.openstore.persistence.model.OpenStoreExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andUserIdEqualTo(userId);
		criteria.andStatusEqualTo("1");
		List<OpenStore> list = openStoreService.list(example);
		if( list.size()>0 ){
			OpenStore openStore = list.get(0);
			tgwId = openStore.getTgwId();
		}
		return tgwId;
	}
}
